Skip to content

feat(ai-security-guard): add Redis-based message deduplication for content moderation#3650

Open
JianweiWang wants to merge 3 commits intohigress-group:mainfrom
JianweiWang:fix_prompt_ai_security_guard
Open

feat(ai-security-guard): add Redis-based message deduplication for content moderation#3650
JianweiWang wants to merge 3 commits intohigress-group:mainfrom
JianweiWang:fix_prompt_ai_security_guard

Conversation

@JianweiWang
Copy link
Copy Markdown
Contributor

Summary

ai-security-guard 插件新增基于 Redis 的消息去重机制,避免对相同内容进行重复的安全检测,提升性能并降低对后端安全检测服务的调用量。

核心设计

  • 去重粒度:按消息级别去重,通过 SHA256(策略指纹 + consumer + role + content + 图片指纹) 生成唯一键
  • 缓存安全:策略指纹包含所有影响检测结果的维度,策略变更时自动失效缓存
  • 降级策略:Redis 不可用时自动关闭去重,Lua 脚本失败降级为逐条写入

变更范围

  • config/config.go - 新增 Redis 去重相关配置
  • lvwang/common/check_helper.go - 新增通用检测辅助工具(含去重逻辑)
  • lvwang/multi_modal_guard/text/openai.go - 多模态检测集成去重
  • lvwang/text_moderation_plus/text/openai.go - 文本审核集成去重
  • utils/utils.go - 新增 SHA256 哈希等工具函数

测试覆盖

新增和更新了多个测试文件(+2000 行测试代码):

  • config/config_test.go
  • lvwang/common/check_helper_test.go
  • lvwang/multi_modal_guard/text/openai_test.go
  • main_test.go
  • utils/utils_test.go

1. 去重粒度: 按消息级别去重,通过 SHA256(策略指纹 + consumer + role + content + 图片指纹) 生成唯一键
2. 缓存安全: 策略指纹包含所有影响检测结果的维度,策略变更时自动失效缓存
3. 降级策略: Redis 不可用时自动关闭去重,Lua 脚本失败降级为逐条写入
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant